public class demo5 {
    public static void main(String[] args) {
        Object A = new Object();
        Object B = new Object();
        Thread t = new Thread(()->{
            synchronized (A){
                System.out.println("A");
                synchronized (B){
                    System.out.println("B");
                }
            }
        });
        Thread t1 = new Thread(()->{
            synchronized (A){
                System.out.println("B");
                synchronized (B){
                    System.out.println("A");
                }
            }
        });
        t.start();
        t1.start();
    }
}
